package com.chmingx.crud.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@RestController
public class RedisController {

    @Autowired
    StringRedisTemplate redisTemplate;

    @GetMapping("/redis")
    public Map<String, String> getUriCount() {
        Set<String> keys = redisTemplate.keys("/*");
        if (keys != null) {
            keys.forEach(System.out::println);
        }
        ValueOperations<String, String> ops = redisTemplate.opsForValue();
        Map<String, String> map = new HashMap<>();
        for (String key : keys) {
            map.put(key, ops.get(key));
        }
        return map;
    }
}
